#include "cropWithParas.h"

namespace sp::Image::Crop{

void registe_cropWithParas(){
    cropWithParas::registe();
}

cropWithParas::cropWithParas(std::vector<std::string> v){ // float w_min, float w_max, float h_min, float h_max
    assert(v.size() == 4);
    name = "cropWithParas";
    class_name = "Image-Crop-cropWithParas";
    w_min = std::stof(v[0]);
    w_max = std::stof(v[1]);
    h_min = std::stof(v[2]);
    h_max = std::stof(v[3]);
    data_type_support.push_back(std::pair<std::vector<uint8_t>, uint8_t>({MAT,RECT},MAT));
}

cropWithParas::cropWithParas(float w_min, float w_max, float h_min, float h_max){
    name = "cropWithParas";
    class_name = "Image-Crop-cropWithParas";
    this->w_min = w_min;
    this->w_max = w_max;
    this->h_min = h_min;
    this->h_max = h_max;
    data_type_support.push_back(std::pair<std::vector<uint8_t>, uint8_t>({MAT,RECT},MAT));
}

cropWithParas::cropWithParas(){
    name = "cropWithParas";
    class_name = "Image-Crop-cropWithParas";
    data_type_support.push_back(std::pair<std::vector<uint8_t>, uint8_t>({MAT,RECT},MAT));
}

cropWithParas::~cropWithParas(){

}

void cropWithParas::registe(){
    Function::Register("Image-Crop-cropWithParas", createObject);
    Function::Register("Image-Crop-cropWithParas", createObject2);
}

Function* cropWithParas::createObject(std::vector<std::string> params){
    return new cropWithParas(params);
}

Function* cropWithParas::createObject2(){
    return new cropWithParas();
}

void cropWithParas::start(){

}

bool cropWithParas::waitForResource(){
    return true;
}

void cropWithParas::process(std::vector<std::vector<Data*>>& data_input, std::vector<Data*>& data_output){
    // 验证输入
    assert(batch_size != 0);
    assert(data_input.size() <= batch_size);
    assert(data_input[0].size() == 1);
    // TODO: 待完善
    assert(false);
}

bool cropWithParas::releaseResource(){
    return true;
}

void cropWithParas::finish(){

}

void cropWithParas::copy(Function* other){
    Function::defaultCopy(other);
    cropWithParas* oth = dynamic_cast<cropWithParas*>(other);
    this->w_min = oth->w_min;
    this->w_max = oth->w_max;
    this->h_min = oth->h_min;
    this->h_max = oth->h_max;
}

};